/**
 * Definition for singly-linked list.
 * struct ListNode {
 *     int val;
 *     struct ListNode *next;
 * };
 */


struct ListNode* middleNode(struct ListNode* head) {
    struct ListNode* last = head;
    struct ListNode* p = head;
    struct ListNode* midNode = head;
    int sz = 0;
    int mid = 0;
    while (p)
    {
        sz++;
        last = p;
        p = p->next;
    }
    mid = sz / 2;
    if (sz == 1)
        return head;
    while (mid)
    {
        midNode = midNode->next;
        mid--;
    }
    return midNode;
}